from pydantic import BaseModel
from typing import Optional, List
from fastapi.responses import JSONResponse

class CommonResponse(BaseModel):
    success: bool
    message: Optional[str] = None
    data: Optional[dict] = None
    error: Optional[str] = None

    class Config:
        schema_extra = {
            "example": {
                "success": True,
                "message": "Operation successful",
                "data": {"key": "value"}
            }
        }


def create_response(
    success: bool,
    message: str = None,
    data: dict = None,
    error: str = None
) -> JSONResponse:
    response = CommonResponse(
        success=success,
        message=message,
        data=data,
        error=error
    )
    return JSONResponse(content=response.model_dump())